// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Gunnar Ritter

#ifndef POPDIAG_CONFIG_APPLEMAIL_PLIST_H_
#define POPDIAG_CONFIG_APPLEMAIL_PLIST_H_

// Including these headers in C++ compilation mode leads to errors.
#ifdef __OBJC__
#import <Foundation/NSDictionary.h>
#endif // __OBJC__

#include <QtCore/QString>
#include <QtCore/QList>

// This is the data found in the plist file, which we return from
// Objective-C as a set structs inside a wrapper class. We keep the
// names identical to those in the plist, so they do not match our
// regular C++ style.
class AppleMailPlist {
 public:
  AppleMailPlist();

  bool Read(QString path);
  const QString& error_message() const { return error_message_; }

  struct DeliveryAccount {
    QString AccountType;
    QString Hostname;
    bool SSLEnabled;
    int SecurityLayerType;
    bool ShouldUseAuthentication;
    QString Username;
  };
  const QList<struct DeliveryAccount>& delivery_accounts() const {
    return delivery_accounts_;
  }

  struct MailAccount {
    QString AccountName;
    QString AccountType;
    int DeleteMessagesOnServerInterval;
    QString DeletionPolicy;
    QList<QString> EmailAddresses;
    QString FullUserName;
    QString Hostname;
    int PortNumber;
    QString SMTPIdentifier;
    bool SSLEnabled;
    int SecurityLayerType;
    QString Username;
  };
  const QList<struct MailAccount>& mail_accounts() const {
    return mail_accounts_;
  }

  int accounts_version() const { return accounts_version_; }

 private:
#ifdef __OBJC__
  void SetDeliveryAccountsFromDict(NSDictionary *dict);
  void SetMailAccountsFromDict(NSDictionary *dict);
#endif  // __OBJC__

  QList<struct DeliveryAccount> delivery_accounts_;
  QList<struct MailAccount> mail_accounts_;
  int accounts_version_;
  QString error_message_;
};

#endif  // POPDIAG_CONFIG_APPLEMAIL_PLIST_H_
